package com.mgr.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mgr.dao.CustomerDao;
import com.mgr.model.Customers;

@Repository
public class CustomerDaoImpl implements CustomerDao {
	@Autowired
	private SessionFactory session;
	
	@Override
	public void add(Customers customer) {
		session.getCurrentSession().save(customer);
	}

	@Override
	public void edit(Customers customer) {
		session.getCurrentSession().update(customer);
	}

	@Override
	public void delete(int custId) {		
		session.getCurrentSession().delete(getCustomers(custId));
	}

	@Override
	public Customers getCustomers(int custId) {
		return (Customers)session.getCurrentSession().get(Customers.class, custId);
	}

	@Override
	public List<Customers> getAllCustomers() {
		return session.getCurrentSession().createQuery("from Customers").list();
	}

	@Override
	public void updateCustomerPass(int id, String newPass) {
		Customers cust = (Customers)session.getCurrentSession().get(Customers.class, id);
		cust.setCustPass(newPass);
	}

}
